{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Leading to Phytoplankton Final Project\n",
    "\n",
    "06/18/2020  \n",
    "ICESAT-2 Hackweek\n",
    "\n",
    "Hackweek Goal: Query, Download, and Visualize coincident ICESat-2, Sentinel-2, and Argo Float data\n",
    "Long Term Goal: Create a package that will download data of interest for a specified time period and bounding box to study ice-ocean interactions and properties. This package will be modular so that other data products can easily be incorporated.\n",
    "\n",
    "First we need to install extra packages to download Sentinel-2 Imagery and import the relevant modules"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Requirement already satisfied: sentinelsat in /srv/conda/envs/notebook/lib/python3.7/site-packages (0.14)\n",
      "Requirement already satisfied: tqdm in /srv/conda/envs/notebook/lib/python3.7/site-packages (from sentinelsat) (4.46.1)\n",
      "Requirement already satisfied: html2text in /srv/conda/envs/notebook/lib/python3.7/site-packages (from sentinelsat) (2020.1.16)\n",
      "Requirement already satisfied: click in /srv/conda/envs/notebook/lib/python3.7/site-packages (from sentinelsat) (7.1.2)\n",
      "Requirement already satisfied: requests in /srv/conda/envs/notebook/lib/python3.7/site-packages (from sentinelsat) (2.23.0)\n",
      "Requirement already satisfied: six in /srv/conda/envs/notebook/lib/python3.7/site-packages (from sentinelsat) (1.15.0)\n",
      "Requirement already satisfied: geomet in /srv/conda/envs/notebook/lib/python3.7/site-packages (from sentinelsat) (0.2.1.post1)\n",
      "Requirement already satisfied: geojson>=2 in /srv/conda/envs/notebook/lib/python3.7/site-packages (from sentinelsat) (2.5.0)\n",
      "Requirement already satisfied: certifi>=2017.4.17 in /srv/conda/envs/notebook/lib/python3.7/site-packages (from requests->sentinelsat) (2020.4.5.1)\n",
      "Requirement already satisfied: idna<3,>=2.5 in /srv/conda/envs/notebook/lib/python3.7/site-packages (from requests->sentinelsat) (2.9)\n",
      "Requirement already satisfied: chardet<4,>=3.0.2 in /srv/conda/envs/notebook/lib/python3.7/site-packages (from requests->sentinelsat) (3.0.4)\n",
      "Requirement already satisfied: urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1 in /srv/conda/envs/notebook/lib/python3.7/site-packages (from requests->sentinelsat) (1.25.9)\n"
     ]
    }
   ],
   "source": [
    "### Install extra packages\n",
    "!pip install sentinelsat"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "### Import modules\n",
    "import sys\n",
    "### Add path to scripts\n",
    "if '/home/jovyan/leading_to_phytoplankton/scripts' not in sys.path:\n",
    "    sys.path.insert(0, '/home/jovyan/leading_to_phytoplankton/scripts')\n",
    "    \n",
    "\n",
    "import numpy as np\n",
    "from sentinelsat import SentinelAPI\n",
    "import shapely.geometry as sg\n",
    "from astropy.time import Time, TimeDelta\n",
    "from tqdm import tqdm\n",
    "import matplotlib.pyplot as plt\n",
    "import h5py, pyproj\n",
    "import readers as rd\n",
    "from icepyx import icesat2data as ipd\n",
    "import cartopy.crs as ccrs\n",
    "import importlib\n",
    "import search_sentinels as ss\n",
    "import rasterio\n",
    "from rasterio.plot import show\n",
    "import pandas as pd\n",
    "from osgeo import gdal\n",
    "\n",
    "import warnings\n",
    "warnings.filterwarnings('ignore')\n",
    "\n",
    "### Magic function to enable interactive plotting\n",
    "%matplotlib widget "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Synthetic Argo Float data is not currently available by API, so we import all float data from the Arctic and Antarctic regions from 2018-2020 here"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "NaN,NaN,2018,6,20,17,45,4.33,0.00079445,28.762,34.726,0.2117\n",
      "NaN,NaN,2018,6,20,17,45,5.6,0.00081808,28.764,34.726,0.2117\n",
      "NaN,NaN,2018,6,20,17,45,11.36,0.00081808,28.771,34.726,0.2117\n",
      "NaN,NaN,2018,6,20,17,45,16.69,0.00095985,28.773,34.726,0.2263\n",
      "NaN,NaN,2018,6,20,17,45,21.73,0.00084171,28.774,34.727,0.2044\n",
      "NaN,NaN,2018,6,20,17,45,26.77,0.00086534,28.774,34.727,0.219\n",
      "NaN,NaN,2018,6,20,17,45,31.73,0.00085352,28.744,34.728,0.2555\n",
      "NaN,NaN,2018,6,20,17,45,36.28,0.00087715,28.715,34.729,0.3139\n",
      "NaN,NaN,2018,6,20,17,45,41.36,0.00086534,28.702,34.727,0.3504\n",
      "NaN,NaN,2018,6,20,17,45,46.71,0.00084171,28.698,34.731,0.3942\n"
     ]
    }
   ],
   "source": [
    "### Define path to sample data\n",
    "data_loc = \"/home/jovyan/shared/leading_to_phytoplankton/\"\n",
    "argo_arc_fn = data_loc+'argo_arc.csv'\n",
    "argo_ant_fn = data_loc+'argo_ant.csv'\n",
    "\n",
    "# Quick check of csv file contents\n",
    "!head $argo_arc_fn"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "-50.01,131.59,2018,9,14,11,17,0.44,-0.00043419,7.505,34.27,-0.00013273\n",
      "-50.01,131.59,2018,9,14,11,17,1.54,-0.00042907,7.5033,34.267,-0.0035173\n",
      "-50.01,131.59,2018,9,14,11,17,2.6,-0.0004344,7.4997,34.271,0\n",
      "-50.01,131.59,2018,9,14,11,17,3.6,-0.00042339,7.493,34.278,0\n",
      "-50.01,131.59,2018,9,14,11,17,4.5,-0.00042338,7.495,34.276,-0.0073\n",
      "-50.01,131.59,2018,9,14,11,17,5.5,-0.00042338,7.4962,34.275,0\n",
      "-50.01,131.59,2018,9,14,11,17,6.5,-0.00042338,7.497,34.276,0\n",
      "-50.01,131.59,2018,9,14,11,17,7.4,-0.00043442,7.498,34.278,0\n",
      "-50.01,131.59,2018,9,14,11,17,8.54,-0.00043393,7.4952,34.277,-0.0069756\n",
      "-50.01,131.59,2018,9,14,11,17,9.54,-0.00042371,7.5001,34.277,-0.000146\n"
     ]
    }
   ],
   "source": [
    "!head $argo_ant_fn"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## In our package, you will define a bounding box and time period for which you want to query ICESat-2 tracks. The script to download the corresponding ICESat-2 data is shown below"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "def download(bbox, timeframe, beam, earthdata_uid, email): \n",
      "    \n",
      "    import os\n",
      "    from icepyx import icesat2data as ipd\n",
      "    from icepyx import core\n",
      "    import readers as rd\n",
      "    \n",
      "    short_name = ATL03 '''fill in with name of whichever DataSet this is a member function of'''\n",
      "    \n",
      "    region.ipd.Icesat2Data(short_name, bbox, timeframe)\n",
      "    region.avail_granules()\n",
      "    \n",
      "    print(region.avail_granules())\n",
      "    if ('y' or 'yes' == input(\"Here's what we've got! Continue? (y/n)\")):\n",
      "        region.earthdata_login(earthdata_uid, email)\n",
      "        \n",
      "        path = './download/' + short_name\n",
      "        region.download_granules(path)\n",
      "        files = region.avail_granules(ids=True)\n",
      "        \n",
      "        print(\"Downloaded! Have a great day!\")\n",
      "    else:\n",
      "        print(\"Nothing was downloaded\")\n",
      "        exit()\n",
      "\n",
      "    \n",
      "    for file in files:\n",
      "        f = h5py.File(path+file, 'r')\n",
      "        df = rd.getATL03(f,beam)\n",
      "        \n",
      "        #trim to bounding box\n",
      "        df_cut=df[bbox]\n",
      "        \n",
      "        #convert time to UTC\n",
      "        epoch=f['/ancillary_data/atlas_sdp_gps_epoch'][0]\n",
      "        df_cut['time']=Time(epoch+df_cut['dt'],format='gps').utc.datetime\n",
      "        \n",
      "        #caculate along track distance\n",
      "        df_cut['AT_dist']=df_cut.x-df_cut.x.values[0]\n",
      "        \n",
      "        #save a dictionary entry in the DataSet\n",
      "        self{file} = df_cut\n",
      "        \n",
      "        "
     ]
    }
   ],
   "source": [
    "### Define bounding box and time frame\n",
    "bbox = [-110, 70, 70, 90]\n",
    "\n",
    "!cat /home/jovyan/leading_to_phytoplankton/scripts/download.py"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Load in a sample ICESat-2 Granule and downsample for quicker plotting"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0\n",
      "        lats       lons          x          y     heights            dt  conf\n",
      "0  80.004734  54.366124  8938896.0  42.220333   89.935242  4.941201e+07     0\n",
      "1  80.004744  54.366109  8938897.0  42.252739 -141.238495  4.941201e+07     0\n",
      "2  80.004736  54.366121  8938897.0  42.207047  168.690918  4.941201e+07     0\n",
      "3  80.004743  54.366112  8938897.0  42.228359   16.640863  4.941201e+07     0\n",
      "4  80.004745  54.366109  8938898.0  42.234760  -29.026579  4.941201e+07     0\n",
      "Number of point measurements: 10730607\n"
     ]
    }
   ],
   "source": [
    "### Load IS2 sample data\n",
    "#f_atl03 = data_loc + \"IS2_S2/ATL03_20190805215948_05930404_002_02.h5\"\n",
    "f_atl03 = data_loc + \"IS2_S2/ATL03_20190726213326_04400404_002_01.h5\"\n",
    "\n",
    "f = h5py.File(f_atl03, 'r')\n",
    "# check to see if it is forward (1)  or backward (0) orientation to know which beam is strong/weak. \n",
    "# (2 is transition phase- don't use these data)\n",
    "print(f['orbit_info/sc_orient'][0])\n",
    "\n",
    "beam = 'gt2l'\n",
    "df03_full = rd.getATL03(f,beam)\n",
    "print(df03_full.head())\n",
    "\n",
    "print(\"Number of point measurements:\", len(df03_full))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Number of point measurements: 10731\n"
     ]
    }
   ],
   "source": [
    "### Downsample ATL03 to speed up test\n",
    "df03 = df03_full[::1000]\n",
    "print(\"Number of point measurements:\", len(df03))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>lats</th>\n",
       "      <th>lons</th>\n",
       "      <th>x</th>\n",
       "      <th>y</th>\n",
       "      <th>heights</th>\n",
       "      <th>dt</th>\n",
       "      <th>conf</th>\n",
       "      <th>time</th>\n",
       "      <th>AT_dist</th>\n",
       "      <th>orbit_number</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>80.004734</td>\n",
       "      <td>54.366124</td>\n",
       "      <td>8938896.0</td>\n",
       "      <td>42.220333</td>\n",
       "      <td>89.935242</td>\n",
       "      <td>4.941201e+07</td>\n",
       "      <td>0</td>\n",
       "      <td>2019-07-26 21:33:25.986627</td>\n",
       "      <td>0.0</td>\n",
       "      <td>4802</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1000</th>\n",
       "      <td>80.007749</td>\n",
       "      <td>54.362400</td>\n",
       "      <td>8939241.0</td>\n",
       "      <td>41.681538</td>\n",
       "      <td>12.426127</td>\n",
       "      <td>4.941201e+07</td>\n",
       "      <td>0</td>\n",
       "      <td>2019-07-26 21:33:26.035227</td>\n",
       "      <td>345.0</td>\n",
       "      <td>4802</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2000</th>\n",
       "      <td>80.008849</td>\n",
       "      <td>54.361042</td>\n",
       "      <td>8939366.0</td>\n",
       "      <td>41.479172</td>\n",
       "      <td>546.315491</td>\n",
       "      <td>4.941201e+07</td>\n",
       "      <td>0</td>\n",
       "      <td>2019-07-26 21:33:26.053327</td>\n",
       "      <td>470.0</td>\n",
       "      <td>4802</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3000</th>\n",
       "      <td>80.009568</td>\n",
       "      <td>54.360142</td>\n",
       "      <td>8939448.0</td>\n",
       "      <td>41.564560</td>\n",
       "      <td>750.957275</td>\n",
       "      <td>4.941201e+07</td>\n",
       "      <td>0</td>\n",
       "      <td>2019-07-26 21:33:26.065027</td>\n",
       "      <td>552.0</td>\n",
       "      <td>4802</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4000</th>\n",
       "      <td>80.010348</td>\n",
       "      <td>54.359147</td>\n",
       "      <td>8939537.0</td>\n",
       "      <td>42.044792</td>\n",
       "      <td>439.323090</td>\n",
       "      <td>4.941201e+07</td>\n",
       "      <td>0</td>\n",
       "      <td>2019-07-26 21:33:26.077426</td>\n",
       "      <td>641.0</td>\n",
       "      <td>4802</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "           lats       lons          x          y     heights            dt  \\\n",
       "0     80.004734  54.366124  8938896.0  42.220333   89.935242  4.941201e+07   \n",
       "1000  80.007749  54.362400  8939241.0  41.681538   12.426127  4.941201e+07   \n",
       "2000  80.008849  54.361042  8939366.0  41.479172  546.315491  4.941201e+07   \n",
       "3000  80.009568  54.360142  8939448.0  41.564560  750.957275  4.941201e+07   \n",
       "4000  80.010348  54.359147  8939537.0  42.044792  439.323090  4.941201e+07   \n",
       "\n",
       "      conf                       time  AT_dist  orbit_number  \n",
       "0        0 2019-07-26 21:33:25.986627      0.0          4802  \n",
       "1000     0 2019-07-26 21:33:26.035227    345.0          4802  \n",
       "2000     0 2019-07-26 21:33:26.053327    470.0          4802  \n",
       "3000     0 2019-07-26 21:33:26.065027    552.0          4802  \n",
       "4000     0 2019-07-26 21:33:26.077426    641.0          4802  "
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "### Convert GPS time to UTC time\n",
    "epoch = f['/ancillary_data/atlas_sdp_gps_epoch'][0]\n",
    "df03['time'] = Time(epoch + df03['dt'],format='gps').utc.datetime\n",
    "\n",
    "### Calculate along track distance relative to the beginning of the cut segment\n",
    "df03['AT_dist'] = df03.x - df03.x.values[0]\n",
    "\n",
    "### Read orbit number\n",
    "df03['orbit_number'] = [f['/orbit_info/orbit_number'][0]] * len(df03)\n",
    "df03.head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Plot the ICESat-2 Granule "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "824c09dd5d5f4198a0563b4e9c9340ee",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Canvas(toolbar=Toolbar(toolitems=[('Home', 'Reset original view', 'home', 'home'), ('Back', 'Back to previous …"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "<matplotlib.colorbar.Colorbar at 0x7f7f2812e150>"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "### Plot data\n",
    "var = 'heights' #choose which variable we want to plot\n",
    "vmin = -10\n",
    "vmax = 30\n",
    "ticks = np.arange(-20,100,5)\n",
    "\n",
    "plt.figure(figsize=(8,8), dpi= 90)\n",
    "ax = plt.axes(projection=ccrs.NorthPolarStereo(central_longitude=0)) # choose polar sterographic for projection\n",
    "ax.coastlines(resolution='50m', color='black', linewidth=1)\n",
    "ax.set_extent([-180, 180, 60, 90], ccrs.PlateCarree())\n",
    "# plt.scatter(df03['lons'][::1000], df03['lats'][::1000],c=df03[var][::1000], cmap='viridis', vmin=vmin,vmax=vmax,transform=ccrs.PlateCarree())\n",
    "plt.scatter(df03['lons'], df03['lats'], c=df03[var], s=1, cmap='viridis', vmin=vmin,vmax=vmax,transform=ccrs.PlateCarree())\n",
    "plt.colorbar(label=var, shrink=0.5, ticks=ticks,extend='both')\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Our package includes a script to locate Sentinel-1 and 2 Imagery that intersects our ICESat-2 Granule of interest within a specified $\\Delta$t"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "\u001b[0;31mSignature:\u001b[0m\n",
       "\u001b[0mss\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0msearch_sentinels\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\u001b[0m\n",
       "\u001b[0;34m\u001b[0m    \u001b[0mplatform_name\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\n",
       "\u001b[0;34m\u001b[0m    \u001b[0mdf\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\n",
       "\u001b[0;34m\u001b[0m    \u001b[0maoi\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\n",
       "\u001b[0;34m\u001b[0m    \u001b[0mdt\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;36m2\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\n",
       "\u001b[0;34m\u001b[0m    \u001b[0muser\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;32mNone\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\n",
       "\u001b[0;34m\u001b[0m    \u001b[0mpwd\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;32mNone\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\n",
       "\u001b[0;34m\u001b[0m    \u001b[0mproj_string\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m'+init=EPSG:3995'\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\n",
       "\u001b[0;34m\u001b[0m    \u001b[0mproduct_type\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;32mNone\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\n",
       "\u001b[0;34m\u001b[0m    \u001b[0mmin_cloud_cover\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\n",
       "\u001b[0;34m\u001b[0m    \u001b[0mmax_cloud_cover\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;36m100\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\n",
       "\u001b[0;34m\u001b[0m    \u001b[0mswath_type\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;32mNone\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\n",
       "\u001b[0;34m\u001b[0m    \u001b[0mf_out\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;32mNone\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\n",
       "\u001b[0;34m\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
       "\u001b[0;31mDocstring:\u001b[0m\n",
       "Search Sentinel-1/2 images overlapping ICESat-2 data within +- dt\n",
       "\n",
       "Parameters:\n",
       "-----------\n",
       "platform_name : str ['Sentinel-1 | Sentinel-2']\n",
       "    name of the platform for which images will be searched\n",
       "df : panda dataframe\n",
       "    ICESat-2 data\n",
       "aoi: str, list\n",
       "    area of interest as WKT string or bounding box[lllon, lllat, urlon, urlat]\n",
       "dt: int, float\n",
       "    difference in hours between CS2 and S2\n",
       "user : str\n",
       "    username to connect to the Copernicus Scientific Hub\n",
       "pwd : str\n",
       "    password to connect to the Copernicus Scientific Hub\n",
       "proj_string: str\n",
       "    projection string to be used with the pyproj module\n",
       "product_type : str\n",
       "    name of the type of product to be searched (more info at https://scihub.copernicus.eu/userguide/)\n",
       "swath_type : str\n",
       "    name of the type of swath to be searched (Sentinel-1 only, more info at https://scihub.copernicus.eu/userguide/)\n",
       "min_cloud_cover: int, float\n",
       "    Minimum cloud coverage in percentage (Sentinel-2 only)\n",
       "max_cloud_cover: int, float\n",
       "    Maximum cloud coverage in percentage (Sentinel-2 only)        \n",
       "f_out : str\n",
       "    path to file where to write results\n",
       "\n",
       "\n",
       "Returns: (to be finished!)\n",
       "--------\n",
       "\u001b[0;31mFile:\u001b[0m      ~/leading_to_phytoplankton/scripts/search_sentinels.py\n",
       "\u001b[0;31mType:\u001b[0m      function\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "importlib.reload(ss)\n",
    "\n",
    "### Retrieve collocated satellite imagery\n",
    "ss.search_sentinels?"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example query of Sentinel-1 and 2 data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [],
   "source": [
    "### Query Sentinel-1\n",
    "#out_s1 = ss.search_sentinels('Sentinel-1', df03, bbox, dt=2, user='adia', pwd='ImageSearchTool2020')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Creating AOI polygon...\n",
      "product_type set to:  S2MSI1C\n",
      "Selecting orbit data inside AOI...\n",
      "N. of orbits/points inside AOI: 1/10731\n",
      "Query for metadata...\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Querying products: 100%|██████████| 189/189 [00:00<00:00, 223.07 products/s]\n",
      "0it [00:00, ?it/s]"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "N. of total images: 189\n",
      "Converting time to astropy objects...\n",
      "Looping over orbits to find intersections within 1h...\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "1it [00:01,  1.54s/it]\n",
      "1it [00:00, 37.14it/s]"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "N. of images within 1h: 189\n",
      "Creating images footprint polygons...\n",
      "Looping over orbits to find intersections...\n",
      "N. of total intersections: 13\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "\n"
     ]
    }
   ],
   "source": [
    "### Query Sentinel-2\n",
    "out_s2 = ss.search_sentinels('Sentinel-2', df03, bbox, dt=1, user='adia', pwd='ImageSearchTool2020')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [],
   "source": [
    "#out_s2\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Visualization"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Plot showing location of all Argo Floats in our dataset"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Load the csv file with Pandas\n",
    "argo_arc_df = pd.read_csv(argo_arc_fn)\n",
    "argo_ant_df = pd.read_csv(argo_ant_fn)\n",
    "# Add column names defined in the metadata\n",
    "argo_arc_df.columns = ['lat', 'lon', 'year', 'month', 'day', 'hour', \n",
    "                   'minute', 'Depth (m)', 'bbp (700 nm)', 'temperature', \n",
    "                   'salinity', 'chlorophyll']\n",
    "argo_ant_df.columns = ['lat', 'lon', 'year', 'month', 'day', 'hour', \n",
    "                   'minute', 'Depth (m)', 'bbp (700 nm)', 'temperature', \n",
    "                   'salinity', 'chlorophyll']\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "039db400cb5b42da8db6ea07ab343d9b",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Canvas(toolbar=Toolbar(toolitems=[('Home', 'Reset original view', 'home', 'home'), ('Back', 'Back to previous …"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "# Create a scatter plot showing data locations\n",
    "plt.figure(figsize=(8,8), dpi= 90)\n",
    "ax = plt.axes(projection=ccrs.PlateCarree()) # choose polar sterographic for projection\n",
    "ax.coastlines(resolution='50m', color='black', linewidth=1)\n",
    "plt.scatter(argo_arc_df['lon'], argo_arc_df['lat'], c= 'r',s=1,transform=ccrs.PlateCarree())\n",
    "plt.scatter(argo_ant_df['lon'], argo_ant_df['lat'], c= 'r',s=1,transform=ccrs.PlateCarree())\n",
    "ax.set_title('Location of Argo Floats');"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Load in an example colocated Sentinel-2 Image and determine the bounding box"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "POLYGON ((509760 8890200, 509760 9000000, 399960 9000000, 399960 8890200, 509760 8890200))\n",
      "EPSG:32614\n"
     ]
    }
   ],
   "source": [
    "#s2_fn = 'IS2_S2/2019085_T11XMK.tif'\n",
    "s2_fn = 'IS2_S2/20190726_T14XMQ.tif'\n",
    "s2_img = rasterio.open(data_loc+s2_fn)\n",
    "s2_bounds  = s2_img.bounds\n",
    "\n",
    "from shapely.geometry import box\n",
    "geom = box(*s2_bounds)\n",
    "print(geom.wkt)\n",
    "print(s2_img.crs)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "55c40cd921dc4fbcb68771dceb4032cb",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Canvas(toolbar=Toolbar(toolitems=[('Home', 'Reset original view', 'home', 'home'), ('Back', 'Back to previous …"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "var= 'heights' #choose which variable we want to plot\n",
    "\n",
    "## we will want to set colorbar parameters based on the chosen variable\n",
    "vmin=-10\n",
    "vmax=30\n",
    "ticks=np.arange(-20,100,5)\n",
    "proj = pyproj.Proj('+init=' + str(s2_img.crs))\n",
    "\n",
    "plt.figure(figsize=(8,8), dpi= 90)\n",
    "ax = plt.axes(projection=ccrs.NorthPolarStereo(central_longitude=0)) # choose polar sterographic for projection\n",
    "ax.coastlines(resolution='50m', color='black', linewidth=1)\n",
    "ax.set_extent([-180, 180, 60, 90], ccrs.PlateCarree())\n",
    "plt.scatter(argo_arc_df['lon'], argo_arc_df['lat'], c= 'r',s=2,transform=ccrs.PlateCarree())\n",
    "plt.scatter(df03['lons'], df03['lats'],c=df03[var], cmap='viridis', vmin=vmin,vmax=vmax,transform=ccrs.PlateCarree())\n",
    "plt.plot(*geom.exterior.xy, color='black', linewidth=1,transform=ccrs.UTM(14))\n",
    "plt.colorbar(label=var, shrink=0.5, ticks=ticks,extend='both');"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Show where ICESat-2 granule crosses the corresponding colocated Sentinel-2 image"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "2d041a509e064b5d8be0ed45f7e453f1",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Canvas(toolbar=Toolbar(toolitems=[('Home', 'Reset original view', 'home', 'home'), ('Back', 'Back to previous …"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "[<matplotlib.lines.Line2D at 0x7f7f1aaf6fd0>]"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "plt.figure(figsize=(8,8), dpi= 90)\n",
    "show(s2_img)\n",
    "\n",
    "\n",
    "x, y = proj(np.array(df03['lons']), np.array(df03['lats']))\n",
    "plt.plot(x[-1500:], y[-1500:], '.r')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Zoom in where we know a melt pond exists\n",
    "### The melt pond in the Sentinel-2 image will be slightly offset from the shown ICESat-2 track due to sea ice drift"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "32d82ae71e7c41d591cd0258912fd04a",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Canvas(toolbar=Toolbar(toolitems=[('Home', 'Reset original view', 'home', 'home'), ('Back', 'Back to previous …"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "lonmin: -103.19261283470591\n",
      "lonmax: -103.04480921439075\n",
      "latmin: 80.77501361105543\n",
      "latmax: 80.79552718811355\n"
     ]
    }
   ],
   "source": [
    "plt.figure(figsize=(8,8), dpi= 90)\n",
    "show(s2_img)\n",
    "x_zoom, y_zoom = proj(np.array(df03_full['lons'][-1500000:]), np.array(df03_full['lats'][-1500000:]))\n",
    "plt.plot(x_zoom, y_zoom, '.r')\n",
    "\n",
    "plt.xlim((425027.75573844597, 427825.9806155204))\n",
    "plt.ylim((8970799.98349305, 8972896.74600312))\n",
    "lonmin, latmin = proj(plt.xlim()[0], plt.ylim()[0], inverse=True)\n",
    "lonmax, latmax = proj(plt.xlim()[1], plt.ylim()[1], inverse=True)\n",
    "print(\"lonmin:\", lonmin)\n",
    "print(\"lonmax:\", lonmax)\n",
    "print(\"latmin:\", latmin)\n",
    "print(\"latmax:\", latmax)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Load in the corresponding ATL07 granule for comparison with ATL03"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "        lats       lons       heights            dt          conf  stype  \\\n",
      "0  79.560703  54.895848  3.402823e+38  4.941200e+07  3.402823e+38      1   \n",
      "1  79.594908  54.856542  3.402823e+38  4.941200e+07  3.402823e+38      1   \n",
      "2  79.643872  54.799941  3.402823e+38  4.941200e+07  3.402823e+38      1   \n",
      "3  79.659694  54.781501  3.402823e+38  4.941200e+07  3.402823e+38      1   \n",
      "4  79.674302  54.764400  3.402823e+38  4.941200e+07  3.402823e+38      1   \n",
      "\n",
      "   ssh_flag         gauss   photon_rate  cloud       mss     ocean       lpe  \\\n",
      "0         0  3.402823e+38  3.402823e+38      5  8.248694 -0.052216  0.004915   \n",
      "1         0  3.402823e+38  3.402823e+38      5  8.327850 -0.053121  0.004916   \n",
      "2         0  3.402823e+38  3.402823e+38      5  8.446589 -0.054317  0.004919   \n",
      "3         0  3.402823e+38  3.402823e+38      5  8.482800 -0.054679  0.004920   \n",
      "4         0  3.402823e+38  3.402823e+38      5  8.515224 -0.055003  0.004920   \n",
      "\n",
      "         ib  \n",
      "0 -0.075599  \n",
      "1 -0.075622  \n",
      "2 -0.075685  \n",
      "3 -0.075697  \n",
      "4 -0.075703  \n",
      "Number of point measurements: 93950\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>lats</th>\n",
       "      <th>lons</th>\n",
       "      <th>x</th>\n",
       "      <th>y</th>\n",
       "      <th>heights</th>\n",
       "      <th>dt</th>\n",
       "      <th>conf</th>\n",
       "      <th>correction</th>\n",
       "      <th>height_corr</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>80.004734</td>\n",
       "      <td>54.366124</td>\n",
       "      <td>8938896.0</td>\n",
       "      <td>42.220333</td>\n",
       "      <td>89.935242</td>\n",
       "      <td>4.941201e+07</td>\n",
       "      <td>0</td>\n",
       "      <td>6.933347e+37</td>\n",
       "      <td>-6.933347e+37</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>80.004744</td>\n",
       "      <td>54.366109</td>\n",
       "      <td>8938897.0</td>\n",
       "      <td>42.252739</td>\n",
       "      <td>-141.238495</td>\n",
       "      <td>4.941201e+07</td>\n",
       "      <td>0</td>\n",
       "      <td>6.933347e+37</td>\n",
       "      <td>-6.933347e+37</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>80.004736</td>\n",
       "      <td>54.366121</td>\n",
       "      <td>8938897.0</td>\n",
       "      <td>42.207047</td>\n",
       "      <td>168.690918</td>\n",
       "      <td>4.941201e+07</td>\n",
       "      <td>0</td>\n",
       "      <td>6.933942e+37</td>\n",
       "      <td>-6.933942e+37</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>80.004743</td>\n",
       "      <td>54.366112</td>\n",
       "      <td>8938897.0</td>\n",
       "      <td>42.228359</td>\n",
       "      <td>16.640863</td>\n",
       "      <td>4.941201e+07</td>\n",
       "      <td>0</td>\n",
       "      <td>6.933942e+37</td>\n",
       "      <td>-6.933942e+37</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>80.004745</td>\n",
       "      <td>54.366109</td>\n",
       "      <td>8938898.0</td>\n",
       "      <td>42.234760</td>\n",
       "      <td>-29.026579</td>\n",
       "      <td>4.941201e+07</td>\n",
       "      <td>0</td>\n",
       "      <td>6.933942e+37</td>\n",
       "      <td>-6.933942e+37</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "        lats       lons          x          y     heights            dt  conf  \\\n",
       "0  80.004734  54.366124  8938896.0  42.220333   89.935242  4.941201e+07     0   \n",
       "1  80.004744  54.366109  8938897.0  42.252739 -141.238495  4.941201e+07     0   \n",
       "2  80.004736  54.366121  8938897.0  42.207047  168.690918  4.941201e+07     0   \n",
       "3  80.004743  54.366112  8938897.0  42.228359   16.640863  4.941201e+07     0   \n",
       "4  80.004745  54.366109  8938898.0  42.234760  -29.026579  4.941201e+07     0   \n",
       "\n",
       "     correction   height_corr  \n",
       "0  6.933347e+37 -6.933347e+37  \n",
       "1  6.933347e+37 -6.933347e+37  \n",
       "2  6.933942e+37 -6.933942e+37  \n",
       "3  6.933942e+37 -6.933942e+37  \n",
       "4  6.933942e+37 -6.933942e+37  "
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from scipy.interpolate import interp1d\n",
    "\n",
    "### Load IS2 sample data\n",
    "#f_atl03 = data_loc + \"IS2_S2/ATL03_20190805215948_05930404_002_02.h5\"\n",
    "f_atl07 = data_loc + \"IS2_S2/ATL07-01_20190726211228_04400401_002_02.h5\"\n",
    "\n",
    "f = h5py.File(f_atl07, 'r')\n",
    "\n",
    "beam = 'gt2l'\n",
    "df07 = rd.getATL07(f,beam)\n",
    "print(df07.head())\n",
    "\n",
    "print(\"Number of point measurements:\", len(df07))\n",
    "\n",
    "# mean sea surface correction - interpolating time with corrections\n",
    "mss_corr=interp1d(df07.dt.values,df07.mss.values)\n",
    "# inverted barometer correction\n",
    "ib_corr=interp1d(df07.dt.values,df07.ib.values)\n",
    "# ocean tide correction\n",
    "ocean_corr=interp1d(df07.dt.values,df07.ocean.values)\n",
    "# long period equilibrium tide correction\n",
    "lpe_corr=interp1d(df07.dt.values,df07.lpe.values)\n",
    "\n",
    "# Apply corrections  at sampling rate of dt from atl03\n",
    "df03_full['correction']=mss_corr(df03_full.dt.values)+ib_corr(df03_full.dt.values)+ocean_corr(df03_full.dt.values)+lpe_corr(df03_full.dt.values)\n",
    "df03_full['height_corr']=df03_full.heights-df03_full.correction # subtract correction from ATL03 heights\n",
    "df03_full.head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Visualize the ATL03 and ATL07 granules together.\n",
    "### Note that the ATL07 data does not capture the melt pond"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "4eeb732e74054992bc8117401ee7d82e",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Canvas(toolbar=Toolbar(toolitems=[('Home', 'Reset original view', 'home', 'home'), ('Back', 'Back to previous …"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "<matplotlib.legend.Legend at 0x7f7f1abc8d50>"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "bbox=(df03_full['lats']>latmin)&(df03_full['lats']<latmax)\n",
    "df03_cut=df03_full[bbox]\n",
    "\n",
    "plt.figure()\n",
    "plt.scatter(df03_cut['lats'], df03_cut['height_corr'], c='r', s=1, label='ATL03')\n",
    "plt.plot(df07['lats'], df07['heights'], '.k', label='ATL07')\n",
    "plt.xlim((latmin, latmax))\n",
    "plt.ylim((-7, 10))\n",
    "plt.xlabel(\"lat [deg]\")\n",
    "plt.ylabel(\"h [m]\")\n",
    "plt.legend()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# This is an example of how our package will work\n",
    "## Once completed, this package will allow the user to extract parameters from coincident ATL03, ATL07, Sentinel-2, and Argo Float data. There will be functionality to correct for sea ice drift.\n",
    "\n",
    "## Parameters that can be extracted include:\n",
    "Melt Pond Depth  \n",
    "Melt Pond Fraction  \n",
    "Sea Ice Roughness  \n",
    "and many many more!"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [],
   "source": [
    "# we need to tell python where to find the package \n",
    "# from datetime import datetime as dt\n",
    "sys.path.append('../scripts/')\n",
    "from colocateddata import *\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Define a bounding box, start and end time"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2020-06-15 00:00:00\n",
      "2020-06-16 00:00:00\n"
     ]
    }
   ],
   "source": [
    "start_time = dt.datetime(2020, 6, 15)\n",
    "end_time = dt.datetime(2020, 6, 16)\n",
    "bounding_box = [-180,180, 60, 90] # lon1, lon2, lat1, lat2\n",
    "print(start_time)\n",
    "print(end_time)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Now we'll create an instance of the object \"Colocateddata\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "bounding box: [-180, 180, 60, 90]\n",
      "Start time: 2020-06-15 00:00:00\n",
      "End time: 2020-06-16 00:00:00\n",
      "Datasets: No datasets have been added yet\n"
     ]
    }
   ],
   "source": [
    "dat = Colocateddata(bounding_box, start_time, end_time)\n",
    "print(dat)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We can see that we now have a clean string representetion of the object showing it's bounding box, and time frame. Now we'll populate it with datasets of interest\n",
    "Let's try to add ATL03 data and Argo floats"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Searching though ATL03\n",
      "Searching though Argo\n",
      "Error: Argo is not a supported dataset\n",
      "Permitted datasets are \n",
      "\tATL03, ATL07\n",
      "search complete\n"
     ]
    }
   ],
   "source": [
    "dat.init_dataset(['ATL03', 'Argo'])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The Argo float data type hasn't yet been implemented, but we can toy with the ATL03 data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "bounding box: [-180, 180, 60, 90]\n",
      "Start time: 2020-06-15 00:00:00\n",
      "End time: 2020-06-16 00:00:00\n",
      "Datasets:\n",
      "\tATL03\n"
     ]
    }
   ],
   "source": [
    "print(dat)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Now suppose we want to visualize the ATL03 height data."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "fe8691f8c92040c2866a5a6500b0612d",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Canvas(toolbar=Toolbar(toolitems=[('Home', 'Reset original view', 'home', 'home'), ('Back', 'Back to previous …"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "dat.datasets['ATL03'].visualize()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Suppose we have added several colocated datasest and want to see how the coincide on the same set of axes"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
   "outputs": [],
   "source": [
    "dat.show_area_overlap()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "In the future, more functionalities will be implemented and the user will ba able to download, and quickly get various parameters from each of the specific dataset types"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python [conda env:notebook] *",
   "language": "python",
   "name": "conda-env-notebook-py"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
